import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:overlay_support/overlay_support.dart';
import 'package:provide/provide.dart';
import 'package:qgchat/common/class/overlay/index.dart';
import 'package:qgchat/common/global/global.dart';

import '../common/global/global.dart';
import 'auth.dart';

///
/// app初始化组件
/// 包括基本设置
/// 状态设置
/// 等等需要提前配置的东西
///

class App extends StatefulWidget {
  App({Key key}) : super(key: key);

  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  void initState() {
    super.initState();
    // 屏幕方向
    SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);

    // statusBar设置为透明，去除半透明遮罩
    SystemChrome.setSystemUIOverlayStyle(Config.statusBarStyle);
  }

  @override
  Widget build(BuildContext context) {
    return ProviderNode(
      providers: Global.providers,
      child: OverlaySupport(
        child: OverlayBuild(
          child: Builder(
            builder: (BuildContext context) {
              Global.context = context;
              return MaterialApp(
                locale: const Locale('zh'),
                navigatorKey: Global.noCtxRoute.navigatorKey,
                onGenerateRoute: Global.router.generator,
                theme: ThemeData(
                  primaryColorBrightness: Brightness.light,
                  scaffoldBackgroundColor: col("FAFAFA"),
                  appBarTheme: AppBarTheme(
                    elevation: 1.0,
                    color: Colors.white,
                  ),
                ),
                home: _WaitCtx(),
              );
            },
          ),
        ),
      ),
    );
  }
}

class _WaitCtx extends StatefulWidget {
  const _WaitCtx({Key key}) : super(key: key);

  @override
  __WaitCtxState createState() => __WaitCtxState();
}

class __WaitCtxState extends State<_WaitCtx> {
  @override
  Widget build(BuildContext context) {
    // 设计稿的尺寸初始化为iphone6
    ScreenUtil.instance = ScreenUtil(
      width: 750,
      height: 1334,
    )..init(context);
    return Auth();
  }
}
